package ar.republicagroup.gestion.dao.jpa;

import ar.republicagroup.gestion.dao.ChequeTipoDAO;
import ar.republicagroup.gestion.entities.ChequeTipo;
import ar.republicagroup.gestion.util.JComboBoxModel;
import ar.republicagroup.gestion.util.JPAUtil;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import javax.swing.DefaultComboBoxModel;

public class ChequeTipoDAOImplJPA implements ChequeTipoDAO{
	
		private EntityManager em;
	
	
	public ChequeTipoDAOImplJPA(){
			em = JPAUtil.getEntityManager();
	}
	
	

	@Override
	public List<ChequeTipo> findEntities() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String insert(ChequeTipo beanChequeTipo) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String update(ChequeTipo beanChequeTipo) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ChequeTipo get(Integer id_chequetipo) {
		if(!em.isOpen()){
                    em = JPAUtil.getEntityManager();
                }
                
                return em.find(ChequeTipo.class, id_chequetipo);
	}

	@Override
	public String delete(Integer id_chequetipo) {
		// TODO Auto-generated method stub
		return null;
	}

    @Override
    public DefaultComboBoxModel combo() {
        Query query             = em.createQuery("SELECT c FROM ChequeTipo c WHERE c.estado = 1",ChequeTipo.class);
       
        List<ChequeTipo> chequeTipoList   = query.getResultList();
        DefaultComboBoxModel model = new DefaultComboBoxModel();
        for(ChequeTipo chequeTipo : chequeTipoList){
            model.addElement(new JComboBoxModel(chequeTipo.getId().toString(), chequeTipo.getTipo()));
        }
        
        return model;
    }

	
	
	

	
}
